Skip to content

Conversation

bdrung
Copy link
Contributor

@bdrung bdrung commented Mar 5, 2025

Fixes #934

Description

Since Python 3.12, the utcnow function is deprecated - see, https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

This commit turns usages of utcnow() into now(UTC).

The feature or problem addressed by this PR

This addresses the issue described in #934

What your changes do and why you chose this solution

The solution is based on the suggestion from official Python docs:
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

Replace datetime.datetime.utcnow() with datetime.datetime.now(datetime.timezone.utc).
At the same time, the pytz dependency is removed in favour of the standard Python functions.

Checklist

  • Checked that no other issues or pull requests exist for the same issue/change
  • Added tests covering the new functionality
  • Updated documentation OR the change is too minor to be documented
  • Updated CHANGELOG.md OR changes are insignificant

Fixes: #934

Since Python 3.12, the utcnow function is deprecated.
see, https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

This commit turns usages of `utcnow()` into `now(timezone.UTC)`.

The solution is based on the suggestion from official Python docs:
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

Replace `datetime.datetime.utcnow()` with `datetime.datetime.now(datetime.timezone.utc)`.
At the same time, the pytz dependency is removed in favour of the standard Python functions.

Signed-off-by: Ivan Kanakarakis <[email protected]>
@c00kiemon5ter c00kiemon5ter merged commit c45eb9d into IdentityPython:master Oct 7, 2025
2 checks passed
@c00kiemon5ter
Copy link
Member

Thank you @bdrung !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pysaml2 raises DeprecationWarning: datetime.datetime.utcnow() when running tests with pytests on python 3.12
2 participants